#ifndef CONVERSE_CONVERSEMESSAGEGROUP_H
#define CONVERSE_CONVERSEMESSAGEGROUP_H

#include "converseabstractdataitem.h"


#include <QObject>
#include <QMap>
#include <QPointer>


namespace Converse {

class AbstractMessage;

class MessageGroup : public AbstractDataItem
{
    Q_OBJECT
public:
    typedef QMap<qint64, QPointer<AbstractMessage> > MessageFinder;

public:
    explicit MessageGroup(QObject *parent = 0);
    explicit MessageGroup(AbstractMessage *message, QObject *parent = 0);
    explicit MessageGroup(const QList<AbstractMessage *> &messageList, QObject *parent = 0);
    explicit MessageGroup(const QVarLengthArray<AbstractMessage *> &messageArray, QObject *parent = 0);
    virtual ~MessageGroup();

private:
    QList<QPointer<AbstractMessage> > m_messageList;
    MessageFinder m_messageFinder;

Q_SIGNALS:
    void messageInserted();
    void messageAppended();
    void dataChanged();

public:
    AbstractDataItem::Type type() const;

public:
    void insert(AbstractMessage *message);
    void append(AbstractMessage *message);

public:
    AbstractMessage *at(int index) const;
    int count() const;
    int size() const;

public:
    qint64 groupId() const;
    qint64 senderId() const;
    qint64 receiverId() const;
    QPixmap avatarPixmap() const;
    const QString &name() const;
    qint64 maximumCreatedTime() const;
    qint64 minimumCreatedTime() const;
    const QList<QPointer<AbstractMessage> > &messageList() const;
};

} // namespace Converse

#endif // CONVERSE_CONVERSEMESSAGEGROUP_H
